package iceforge;

import java.io.File;
import java.io.IOException;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;

public final class AutoDeploy {
  /**  
   * @param args  
   * @throws IOException 
   */  
  public static void deploy() {  
    new Thread(new Runnable() {
      public void run() {
        File buildFile = new File("build.xml");   
        //创建一个默认的监听器,监听项目构建过程中的日志操作
        DefaultLogger consoleLogger = new DefaultLogger();
        consoleLogger.setErrorPrintStream(System.err);
        consoleLogger.setOutputPrintStream(System.out);
        consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
        Project p = new Project();   
        p.addBuildListener(consoleLogger);
        try {   
         p.fireBuildStarted();   
         p.init();   
         ProjectHelper helper = ProjectHelper.getProjectHelper();   
         helper.parse(p, buildFile);   
         p.executeTarget(p.getDefaultTarget());   
         p.fireBuildFinished(null);   
        } catch (BuildException e) {   
         p.fireBuildFinished(e);   
        } 
      }
    }).start();
  
  }   
}
